package com.zhengke.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhengke.dao.IDiscountDao;
import com.zhengke.pojo.CommonGoods;
import com.zhengke.pojo.GoodsDetails;
import com.zhengke.pojo.MallServiceGoods;
import com.zhengke.pojo.MallSupplier;
import com.zhengke.pojo.SysDictionaryItem;
import com.zhengke.pojo.TvOrder;
import com.zhengke.pojo.TvOrderGoods;
import com.zhengke.pojo.TvUserOpera;
import com.zhengke.pojo.archie.TvUser;


/****************************
 * 	创建时间  2020年1月13日 上午8:55:48
 *	项目名称 tvmallws Maven Webapp
 * 	@author 刘荣乾
 *	@version 1.0 
 *	文件名称：DiscountServiceImpl.java
 *	类说明：  查询打折商品
 ****************************/
@Service
public class DiscountServiceImpl implements IDiscountService {
	@Autowired
	private IDiscountDao dao;
	

	/**
	 * 	查询打折商品
	 */
	@Override
	public List<Map<String, Object>> findDiscount(String id) {
 
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("StationId", id);
		List<Map<String, Object>> maps = dao.findDiscount(map);
		
		return maps;
	}


	/**
	 * 查询商品详情
	 * @param goodsId
	 * @return
	 */
	@Override
	public List<Map<String, Object>> findGoodsDetail(String goodsId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("goodsId", goodsId);
		return dao.findGoodsDetail(map);
	}

	/**
	 * 查询打包商品详情
	 * @param goodsId
	 * @return
	 */
	@Override
	public List<Map<String, Object>> findGoodsDetail2(String goodsId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("goodsId", goodsId);
		
		return dao.findGoodsDetail2(map);
	}

	/**
	 * 查询打包数量
	 * @param object
	 * @return
	 */
	@Override
	public List<Map<String, Object>> findBaleGoods(String object) {
		// TODO Auto-generated method stub
		return dao.findBaleGoods(object);
		
	}



	/**
	 * 	查询商品
	 * @param goodsId
	 * @return
	 */
	@Override
	public CommonGoods findCommonGoodsById(String goodsId) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("goodsId", goodsId);
		
		return dao.findCommonGoodsById(map);
	}


	/**
	 * 	查询商品详情
	 * @param goodsId
	 * @return
	 */
	@Override
	public GoodsDetails findGoodsDetailsById(String goodsId) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("goodsId", goodsId);
		return dao.findGoodsDetailsById(map);
	}


	/**
	 * 查询TvUser
	 * @param user
	 * @return
	 */
	@Override
	public TvUser findTvUser(String user_id) {

		TvUser user = new TvUser();
		user.setUser_id(user_id);
		
		return dao.findTvUser(user);
	}


	/**
	 * 	更新TVUser
	 * @param user
	 */
	@Override
	public void updateUser(TvUser user) {
		// TODO Auto-generated method stub
		dao.updateTvUser(user);
	}



	/**
	 *	根据dic_id,status,id_selected查询SysDictionaryItem
	 * @param map
	 * @return
	 */
	@Override
	public List<SysDictionaryItem> finDictionaryItems(String dicId) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dicId", dicId);
		
		
		return dao.finDictionaryItems(map);
	}


	
	/**
	 * 	根据stationID,goodsId,goodsType 查询MallServiceGoods
	 * @param map
	 * @return
	 */
	@Override
	public List<MallServiceGoods> findServiceGoods(String stationId, String goodsId, String goodsType) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		//map.put("stationId", Integer.parseInt(stationId));
		//map.put("goodsId", Integer.parseInt(goodsId));
		//map.put("goodsType", Integer.parseInt(goodsType));
		map.put("stationId",stationId );
		map.put("goodsId",goodsId );
		map.put("goodsType", goodsType);
		
		return dao.findServiceGoods(map);
	}

	/**
	 * 生成订单号码
	 */
	@Override
	public String createOrderSn(String tvnNo) {
		// TODO Auto-generated method stub
		return tvnNo+String.format("%013d",(new Date().getTime()));
	}

	/**
	 * 生成订单
	 * @param to
	 * @param tog
	 * @param msg 
	 */
	@Override
	public void createOrder(TvOrder to, TvOrderGoods tog, MallServiceGoods msg) {

		if (to!=null) {
			dao.insertTvOrder(to);
			if (tog!=null) {
				tog.setOrderId(to.getOrderId());
				dao.insertTvOrderGoods(tog);
			}
		}
		if (msg!=null) {
			dao.updateMallServiceGoods(msg);
		}
		
	}

	/**
	 * 供应商信息
	 * @return
	 */
	@Override
	public MallSupplier findMallSupplier(Integer supplierId) {
		// TODO Auto-generated method stub
		MallSupplier mallSupplier = new MallSupplier();
		mallSupplier.setSupplierId(supplierId);
		return dao.findMallSupplier(supplierId);
	}


	@Override
	public String queryParamValueByItemId(String itemId) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("itemId",itemId);
		if (itemId==""||itemId==null) {
			return null;
		}
		SysDictionaryItem dicItem = dao.finDictionaryItemsByItemId(map);
		if(dicItem!=null) {
			return dicItem.getParamValue();
		}
		
		return null;
	}


	@Override
	public void insertSelective(TvUserOpera tvUserOpera) {
		// TODO Auto-generated method stub
		dao.insertSelective(tvUserOpera);
		
	}



}
